/* JavaScript Validator class
 * by Csatlos Sandor <csatlos.sandor@gmail.com>
 * Version: 0.1 
 * Date 08.11.2008
 */
 


function Validator()
{
	var fields = [];
	this.addField = addField;
	this.validate = validate;

	function addField(field)
	{
		fields.push(field);		
	}

	function validate()
	{//alert(fields.length);

		error = '';
		for ( i = 0; i < fields.length; i++ )
		{
			var elem = document.getElementById(fields[i].id);
			//alert(document.getElementById(fields[i].id).value+elem.type);
			if ( elem )
			{
				if ( elem.type == 'text')
					if (elem.value == '')
						error += fields[i].message+'\n';
				if ( elem.type == 'select-one')
					if (elem.selectedIndex == 0 )
						error += fields[i].message+'\n';
				if ( elem.type == 'checkbox')
					if (elem.checked == false )
						error += fields[i].message+'\n';
				if ( elem.type == 'textarea')
					if (elem.value == '')
						error += fields[i].message+'\n';
			}
		}

		if ( error == '' )
			return true;
		else
		{
			alert  ( error);
			return false;
		}
	}
}

function Field(id, message)
{
	this.id = id;
	this.message = message;
}

